package com.common.utils.parse;

import org.apache.commons.lang3.StringUtils;

import com.gzcwt.entity.Limit;
 


/**
 * @author: feijinbo
 * @createTime: 2011-12-19 下午3:28:47
 * @version: 1.0
 * @desc :
 */
public class LimitUtil {

	/**
	 * limit对象校验
	 * 
	 * @param str
	 * @return
	 * @throws Exception
	 */
	public static Limit getLimit(String str) throws Exception {
		try {
			Limit limit = new Limit();
			if (StringUtils.isEmpty(str)) {
				limit.setOffset(-1);
				limit.setLength(-1);
			} else {
				String[] arr = str.split(",");
				if (arr == null || arr.length != 2) {
					limit = null;
				} else {
					limit.setOffset(Integer.parseInt(arr[0]));
					limit.setLength(Integer.parseInt(arr[1]));
				}
			}
			return limit;
		} catch (Exception e) {
			// TODO: handle exception
			return null;
		}
	}

}
